<?php

include 'C:\\xampp\htdocs\AI-VAS-WEBSITE\trunk\dao_class\User.php';
//include 'C:\\xampp\htdocs\AI-VAS-WEBSITE\trunk\dao_class\UserDao.php';
include 'C:\\xampp\htdocs\AI-VAS-WEBSITE\trunk\dao_class\Datasource.php';


$dbHost = "localhost";
$dbName = "ai-vas";
$dbuser = "root";
$dbpasswd = "";

//connect to the database

$connect = new Datasource($dbHost, $dbName, $dbuser, $dbpasswd);
$user = new User();
//$userdao = new UserDao();
if (isset($_POST['login'])) {
    if ((!empty($_POST['pseudo'])) || (!empty($_POST['pwd']))) {
        $user->setPseudo($_POST['pseudo']);
        $user->setPassword($_POST['pwd']);

        $sql = "SELECT password FROM user WHERE pseudo='" .mysql_real_escape_string(md5($user->getPseudo())) . "'";
       
        $result = mysql_fetch_assoc($connect->execute($sql));

        if ($result['password'] != md5($user->getPassword())) {
            //echo "Unwahres Konto oder Passwort .Danke zu wiederholen.";
            include('login.php');
            exit;
             echo mysql_num_rows($connect->execute($sql));
        } else { 
            session_start();
            $_SESSION['pseudo'] = $user->getPseudo();
            $_SESSION['vornahme']=$user->getVorname();
            $_SESSION['authenticated'] ='yes';                        
      //header('Location: index.php');
        echo   " <script>window.location='index.php'</script>"; 
		exit();  
          
        }
    }
}
?>